﻿using blackhouse.BlackApart.WebNemo;
using blackhouse.WebNemo.Web;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace blackhouse.StareKino.Web.Walk3DHand {
    public partial class Preview : System.Web.UI.Page {

        #region Fields

        private int apartmentTypeId;
        private NemoApartmentType apartmentType;

        #endregion

        #region Methods

        protected override void OnLoad(EventArgs e) {
            base.OnLoad(e);

            this.ReadParameters();
            if (this.SetInstance())
                this.PopulateView();
        }

        private void ReadParameters() {
            Int32.TryParse(Request["ati"], out this.apartmentTypeId);
        }

        private bool SetInstance() {
            if (this.apartmentTypeId > 0) {
                this.apartmentType = new NemoApartmentType(this.apartmentTypeId);
                return this.apartmentType.Exists() && this.apartmentType.IsNotNull("spacer");
            }
            else
                return false;
        }

        private void PopulateView() {
            ClientScriptManager scriptManager = Page.ClientScript;
            scriptManager.RegisterClientScriptInclude(typeof(Preview), "swfobject", "swfobject.js");
            scriptManager.RegisterClientScriptBlock(typeof(Preview), "walkprev", "<script type=\"text/javascript\">"
        + "swfobject.registerObject('pnlContent', '10.0.0', 'expressInstall.swf');"
        + "</script>", false);

            string s = String.Format(@"<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' width='100%' height='100%' id='pnlContent'>
                <param name='movie' value='{0}' />
                <!--[if !IE]>-->
                <object type='application/x-shockwave-flash' data='{0}' width='100%' height='100%'>
                    <!--<![endif]-->
                    <a href='http://www.adobe.com/go/getflashplayer'>
                        <img src='http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif' alt='Get Adobe Flash player' />
                    </a>
                    <!--[if !IE]>-->
                </object>
                <!--<![endif]-->
            </object>", this.apartmentType.GetPreviewUrl("spacer"));

            this.ltlSwfContent.Text = s;
        }

        #endregion

    }
}